package com.springboot.springbootweb.Async;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

@Service
public class AsyncText {

    /**
     * 方法描述
     *
     * @since: 1.0
     * @param: []
     * @return: void
     * @author: gwj
     * @date: 2021/9/10
     */
    @Async
    public void asyncMethodWithVoidReturnType() {
        try {
            Thread.sleep(5000);
            System.out.println("Execute method asynchronously. "
                    + Thread.currentThread().getName());
        } catch (InterruptedException e) {

        }
    }

    @Async("asyncServiceExecutor")
    public Future<String> asyncMethodWithReturnType() {
        System.out.println("Execute method asynchronously - "
                + Thread.currentThread().getName());
        try {
            Thread.sleep(5000);
            return new AsyncResult<String>("hello world !!!!");
        } catch (InterruptedException e) {
            //
        }
        return null;
    }
}
